package com.jht.bletool2java.characteristic.userdata;

import android.bluetooth.BluetoothGattCharacteristic;

import androidx.annotation.Keep;


import com.jht.bletool2java.characteristic.TranslateData;
import com.jht.bletool2java.util.ByteUtil;

import top.codestudy.annotation_uuid.MyUUID;

@Keep
@MyUUID(uuid = "00002a8e-0000-1000-8000-00805f9b34fb")
public class Height implements TranslateData {
    private static final String TAG = "Height";
    private String height = "";
    private byte[] value;
    private boolean isInvalidData = false;
    public Height() {
    }

    public Height(BluetoothGattCharacteristic characteristic) {
        value = characteristic.getValue();
        int i = ByteUtil.bytes2ToInt(value,0);
        height += i;
    }

    public Height(byte[] value) {
        this.value = value;
        int i = ByteUtil.bytes2ToInt(value,0);
        height += i;
    }

    @Override
    public String convert2String() {
        return "Height: " + height + " centimeter;"+"\n";
    }

    @Override
    public String merge(TranslateData translateData) {
        return null;
    }
    @Override
    public boolean hasMoreData() {
        return false;
    }

    @Override
    public byte[] getData() {
        return value;
    }

    @Override
    public boolean isInvalidData() {
        return isInvalidData;
    }

    @Override
    public void parseData(BluetoothGattCharacteristic characteristic, byte[] value) {
        isInvalidData = (value == null || value.length < 2);
        if (isInvalidData){
            //非法数据
            this.value = value;
            height  = "";
        }else {
            this.value = value;
            int i = ByteUtil.bytes2ToInt(value,0);
            height  = ""+i;
        }

    }
}
